﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MusicPlow
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string amazoneKeywords = Request.QueryString["ToAmazon"];
            if (!string.IsNullOrEmpty(amazoneKeywords))
            {
                string redirectTo = string.Format(
                    "http://www.amazon.com/s/?_encoding=UTF8&x=0&redirect=true&tag={0}&linkCode=ur2&y=0&camp=1789&rd=1&creative=390957&field-keywords={1}&url=search-alias%3Ddigital-music",
                    "musi0a0e1-20",
                    HttpUtility.UrlEncode(amazoneKeywords));
                Response.Redirect(redirectTo, true);
            }

            string itunesKeywords = Request.QueryString["ToITunes"];
            if (!string.IsNullOrEmpty(itunesKeywords))
            {
                var itunesTask = ITunes.GetStoreLink(itunesKeywords);
                itunesTask.Wait();
                
                Response.Redirect(itunesTask.Result.Result, true);
            }

        }
    }
}
